package com.scrcu.cloud.wechat.home.endpoint.customer.controller;

import com.scrcu.cloud.wechat.home.endpoint.common.model.RestResponse;
import com.scrcu.cloud.wechat.home.endpoint.customer.service.IBookService;
import com.scrcu.cloud.wechat.home.endpoint.customer.dto.PreBookInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Slf4j
@RestController
@RequestMapping("/book")
public class BookController {

    @Resource
    private IBookService ibookService;

    @GetMapping("/getAllDays4Month")
    @ResponseBody
    public RestResponse getAllDays4Month(@RequestParam("year") String year, @RequestParam("month") String month){
        return ibookService.getAllDays4Month(Integer.parseInt(year), Integer.parseInt(month));
    }

    @GetMapping("/getAllDays4Month2")
    @ResponseBody
    public RestResponse getAllDays4Month2(@RequestParam("year") String year, @RequestParam("month") String month){
        return ibookService.getAllDays4Month2(Integer.parseInt(year), Integer.parseInt(month));
    }

    @PostMapping("/submitBook")
    @ResponseBody
    public RestResponse submitBook(@RequestBody PreBookInfo bookInfo){
        return ibookService.submitBook(bookInfo);
    }

    @PostMapping("/getBookInfo")
    public RestResponse getBookInfo(@RequestParam("openid") String openid,
                                    @RequestParam("status") String status){
        return ibookService.getBookInfo(openid,status);
    }

    @PostMapping("/cancelBook")
    public RestResponse cancelBook(@RequestParam("bookid") String bookid,
                                   @RequestParam(name = "uid",required = false) String uid){
        return ibookService.cancelBook(bookid,uid);
    }

    @PostMapping("/adToFavor")
    public RestResponse adToFavor(@RequestParam("map_id") String map_id,
                                   @RequestParam(name = "openid") String uid){
        return ibookService.adToFavor(map_id,uid);
    }

    @PostMapping("/getFavorList")
    public RestResponse getFavorList(@RequestParam(name = "openid") String uid){
        return ibookService.getFavorList(uid);
    }

    @PostMapping("/judgeFavor")
    public RestResponse judgeFavor(@RequestParam("map_id") String map_id,
                                  @RequestParam(name = "openid") String uid){
        return ibookService.judgeFavor(map_id,uid);
    }

    @PostMapping("/getBooksByInst")
    public RestResponse getBooksByInst(@RequestParam("map_id") String map_id,@RequestParam("year") String year,
                                       @RequestParam("month") String month,@RequestParam("day") String day){
        log.info(map_id);
        log.info(year);
        log.info(month);
        log.info(day);
        return ibookService.getBooksByInst(map_id,Integer.parseInt(year),Integer.parseInt(month),Integer.parseInt(day));
    }


}
